//
//  DURecommendViewController.m
//  toutiao
//
//  Created by duyujin1 on 2021/7/21.
//

#import "DURecommendViewController.h"

@interface DURecommendViewController ()<UIGestureRecognizerDelegate,UIScrollViewDelegate>

@end

@implementation DURecommendViewController

-(instancetype) init{
    if(self=[super init]){
        NSString * title=NSLocalizedString(@"recommend", nil);
        self.tabBarItem.title=title;
        self.tabBarItem.image=[UIImage imageNamed:@"icon.bundle/like@2x.png"];
        self.tabBarItem.selectedImage=[UIImage imageNamed:@"icon.bundle/like_selected@2x.png"];
        self.navigationItem.title=title;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIScrollView * scrollView=[[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.backgroundColor=[UIColor grayColor];
    scrollView.contentSize=CGSizeMake(self.view.bounds.size.width*5, self.view.bounds.size.height);
    
    NSArray * colorArray=@[[UIColor redColor],[UIColor blueColor],[UIColor yellowColor],[UIColor lightGrayColor],[UIColor grayColor]];
    
    for (int i=0; i<5; i++) {
        [scrollView addSubview:({
            UIView * view=[[UIView alloc] initWithFrame:CGRectMake(scrollView.bounds.size.width*i, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];
            
            [view addSubview:({
                UIView * view=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
                view.backgroundColor=[UIColor yellowColor];
                UITapGestureRecognizer * tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewClick)];
                tapGesture.delegate=self;
                [view addGestureRecognizer:tapGesture];
                view;
            })];
            
            view.backgroundColor=[colorArray objectAtIndex:i];
            view;
        })];
    }
    
    //scrollView.pagingEnabled=YES;
    
    [self.view addSubview:scrollView];
}

-(void)viewClick{
    NSURL * urlScheme=[NSURL URLWithString:@"languageScheme://"];
    //只能判断白名单内的app是否已经安装
    BOOL canOpenURL=[[UIApplication sharedApplication] canOpenURL:urlScheme];
    if(canOpenURL){
        //通过scheme唤起其他app
        [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:^(BOOL success) {
            NSLog(@"");
        }];
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES;
}

@end
